<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>修改密码</title>
    <link href="../css/bootstrap.min.css" rel="stylesheet"/>
    <link href="../css/font-awesome.min.css" rel="stylesheet">
    <link href="../css/templatemo_main.css" rel="stylesheet">
    <link href="../css/element/index.css" rel="stylesheet">



    <style>
        .navbar-inverse{
            background-color: #428bca;
            border: none;
        }
        .logo h1{
            color: white;
        }

        .templatemo-submenu li a{
            margin-left: 35px;
        }

        [v-cloak]{
            display: none;
        }

    </style>
</head>
<body style="background-color: #E2E2E2;">
<div id="wrapper"  v-cloak>
    <div class="navbar navbar-inverse" role="navigation">
        <div class="navbar-header">
            <div class="logo"><h1>电动甄选</h1></div>
            <a href="/front/index.html">
                <i class="fa fa-desktop" style="color: white; font-size: 18px;margin-left:40px; ">

                </i>
            </a>
        </div>
        <div class="dropdown" style="display: inline-block;height: 100%;line-height: 50px;float: right;margin-right: 50px;font-size: 16px;">
            <div class="dropdown-toggle" data-toggle="dropdown"style="cursor: pointer;color: white;">
                <i class="fa fa-user" style="margin-right: 5px;font-size: 18px;"></i>{{user.name}}
                <span class="caret"></span>
            </div>
            <ul class="dropdown-menu" style="min-width: 120px;margin-left: -20px;">
                <li><a href="javascript:void(0)"@click="personalPage"><i class="fa fa-user fa-fw"></i>个人信息</a></li>
                <li><a href="javascript:void(0)"@click="logout"> <i class="fa fa-sign-out fa-fw"></i>退出</a></li>
            </ul>
        </div>
    </div>
    <div class="template-page-wrapper">
        <div class="navbar-collapse collapse templatemo-sidebar">
            <ul class="templatemo-sidebar-menu" id="menu-id">
                <li><a href="index.html"><i class="fa fa-home"></i>首页 </a> </li>
                <li class="sub open">
                    <a href="javascript:;">
                        <i class="fa fa-navicon"></i>信息管理
                        <div class="pull-right"><span class="caret"></span></div>
                    </a>
                    <ul class="templatemo-submenu">
                        <li v-if="authority.indexOf(1) != -1">
                            <a href="adminInfo.html">管理员信息</a>
                        </li>
                        <li v-if="authority.indexOf(2) != -1">
                            <a href="workerInfo.html">工作人员信息</a>
                        </li>
                        <li v-if="authority.indexOf(3) != -1">
                            <a href="userInfo.html">用户信息</a>
                        </li>
                        <li v-if="authority.indexOf(4) != -1">
                            <a href="videoInfo.html">新能源汽车介绍</a>
                        </li>
                        <li v-if="authority.indexOf(5) != -1">
                            <a href="richtextInfo.html">新能源汽车详细信息</a>
                        </li>
                        <li v-if="authority.indexOf(6) != -1">
                            <a href="messageInfo.html">汽车论坛</a>
                        </li>
                        <li v-if="authority.indexOf(1000001) != -1">
                            <a href="noticeInfo.html">公告信息</a>
                        </li>
                        <li v-if="authority.indexOf(1000009) != -1">
                            <a href="typeInfo.html">商品类型信息</a>
                        </li>
                        <li v-if="authority.indexOf(1000010) != -1">
                            <a href="goodsInfo.html">商品详情信息</a>
                        </li>
                        <li v-if="authority.indexOf(1000011) != -1">
                            <a href="orderInfo.html">订单信息</a>
                        </li>
                        <li v-if="authority.indexOf(1000012) != -1">
                            <a href="commentInfo.html">评价信息</a>
                        </li>
                        <li v-if="authority.indexOf(1000013) != -1">
                            <a href="richtextInfoComment.html">汽车评论</a>
                        </li>
                        <li>
                            <a href="javascript:void(0)" @click="personalPage">个人信息</a>
                        </li>

                    </ul>
                </li>
                <li>
                    <a href="updatePassword.html"><i class="fa fa-unlock-alt" class="active"></i>修改密码 </a>

                </li>
                <li>
                    <a href="javascript:void(0)" @click="logout"><i class="fa fa-power-off"></i>退出登录 </a>

                </li>
            </ul>
        </div>
        <div class="templatemo-content-wrapper">
            <div class="templatemo-content">
                <div class="row">
                    <div class="col-md-12">
                        <div class="panel panel-default">
                            <div class="panel-heading">
                               修改密码
                            </div>
                            <div class="panel-body">
                                <form style="width: 300px">
                                    <input type="hidden" id="id" name="id" v-model="entity.id">
                                    <div class="form-group input-group">
                                        <span class="input-group-addon"><i class="fa fa-lock"></i> </span>
                                        <input type="password" class="form-control" v-model="entity.password" placeholder="原密码">
                                    </div>
                                    <div class="form-group input-group">
                                        <span class="input-group-addon"><i class="fa fa-lock"></i> </span>
                                        <input type="password" class="form-control" v-model="entity.newPassword" placeholder="新密码">
                                    </div>
                                    <div class="form-group input-group">
                                        <span class="input-group-addon"><i class="fa fa-lock"></i> </span>
                                        <input type="password" class="form-control" v-model="entity.new2Password" placeholder="确认新密码">
                                    </div>
                                    <div style="text-align: center">
                                        <button type="button" class="btn btn-primary" @click="updatePassword()">提交</button>
                                    </div>
                                </form>

                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="../js/jquery.min.js"></script>
<script src="../js/bootstrap.min.js"></script>
<script src="../js/templatemo_script.js"></script>
<script src="../js/my.js"></script>
<script src="../js/vue2.6.11/vue.min.js"></script>
<script src="../js/vue2.6.11/axios.js"></script>
<script src="../js/echarts.min.js"></script>
<script src="../js/element/index.js"></script>
<script>
    function msg(type,msg) {
        Vue.prototype.$message({
            type: type,    //success(成功),warning(警告),error(错误)
            message: msg,
            duration: 1000,
            offset: 100,
            center: true
        })
    }

    new Vue({
        el:"#wrapper",
        data:{
            user: {},
            authority: [],
            objs: [],    //查询的列表
            entity: {},
            permission: [],    //当前页面权限列表


        },
        created: function (){
            this.loadData();
            this.user = JSON.parse(localStorage.getItem('user'));

            axios.get("/authority").then(res =>{
                if (res.data.code ==='0'){
                    this.authority =res.data.data;

                }else {
                    msg('error',res.data.msg);
                }
            });
        },
        methods: {
            //退出登录
            logout(){
                logout();
            },
            //查询用户信息
            loadData(){
                axios.get("/getAccountInfo").then(res =>{
                    if (res.data.code ==='0'){
                        this.entity =res.data.data;

                    }else {
                        msg('error',res.data.msg);
                    }
                });
            },

            //修改密码提交到后台
            updatePassword(){
                if (!this.entity.password || this.entity.password === ''){
                    msg('warning','请输入原密码');
                    return;
                }
                if (!this.entity.newPassword || this.entity.newPassword === ''){
                    msg('warning','请输入新密码');
                    return;
                }
                if (!this.entity.new2Password || this.entity.new2Password === ''){
                    msg('warning','请确认新密码');
                    return;
                }
                if (this.entity.newPassword !==this.entity.new2Password){
                    msg('warning','两次输入新密码不一致');
                    return;
                }
                axios.put('/updatePassword',this.entity).then(res =>{
                    if (res.data.code ==='0'){
                        alert('密码修改成功');
                        logout();
                    }else {
                        msg('error',res.data.msg);
                    }
                });
            },

        }

    });
</script>
</body>
</html>